export function isNull(obj) {
  // 为空返回false 不为空返回true
  switch (typeof obj) {
    case 'string':
      return !(obj.trim() == '')
    case 'undefined':
      return false
    case 'object':
      if (Array.isArray(obj) && obj.length === 0) {
        return false
      } else if (obj && Object.keys(obj).length === 0) {
        return false
      } else if (obj == null || obj == undefined) {
        return false
      } else {
        return true
      }
  }
  return true
}

// 对象判空清除
export function clearnNull(obj) {
  for (let k in obj) {
    if (!isNull(obj[k])) {
      delete obj[k]
    }
  }
  return obj
}

// 清空对象属性
export function clearAttr(obj) {
  for (let k in obj) {
    obj[k] = null
  }
  return obj
}

// 将一个对象赋值给另一个对象
export function assignAttr(obj, targetObj) {
  let targetKeys = Object.keys(targetObj)
  let keys = Object.keys(obj)
  targetKeys.forEach((k) => {
    if (keys.includes(k)) {
      targetObj[k] = obj[k]
    }
  })
}
